package cn.stylefeng.guns.modular.cb.controller;

import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
import cn.stylefeng.guns.base.auth.model.LoginUser;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.cb.entity.CbEducation;
import cn.stylefeng.guns.modular.cb.model.params.CbEducationParam;
import cn.stylefeng.guns.modular.cb.model.result.CbEducationResult;
import cn.stylefeng.guns.modular.cb.service.CbEducationService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 控制器
 * 教育经历
 * @author wj
 * @Date 2021-01-06 21:06:43
 */
@RestController
@RequestMapping("/api/education")
public class CbEducationController extends BaseController {

    private static Logger logger = LoggerFactory.getLogger(CbEducationController.class);

    @Autowired
    private CbEducationService cbEducationService;


    /**
     * 新增接口
     *
     * @author wj
     * @Date 2021-01-06
     */
    @RequestMapping("/addItem")
    public ResponseData addItem(CbEducationParam cbEducationParam) {
//        LoginUser user = LoginContextHolder.getContext().getUser();
//        CbEducationParam param = new CbEducationParam();
//        param.setCode(cbEducationParam.getCode());
//        param.setCreateUser(user.getId());
//        try{
//            CbEducationResult result = cbEducationService.getCbEducation(param);
//            if (result!=null){
//                return ResponseData.error("该学历已存在!");
//            }
//        }catch (Exception e) {
//            logger.error("add education error: ", e);
//        }
        this.cbEducationService.add(cbEducationParam);
        return ResponseData.success();
    }


    /**
     * 新增接口
     *
     * @author wj
     * @Date 2021-01-06
     */
    @RequestMapping("/add_list")
    public ResponseData addList(CbEducationParam cbEducation) {
        for (CbEducationParam item: cbEducation.getParmaList()){
            this.cbEducationService.add(item);
        }
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author wj
     * @Date 2021-01-06
     */
    @RequestMapping("/editItem")
    public ResponseData editItem(CbEducationParam cbEducationParam) {
        this.cbEducationService.update(cbEducationParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author wj
     * @Date 2021-01-06
     */
    @RequestMapping("/delete")
    public ResponseData delete(CbEducationParam cbEducationParam) {
        this.cbEducationService.delete(cbEducationParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author wj
     * @Date 2021-01-06
     */
    @RequestMapping("/detail")
    public ResponseData detail(CbEducationParam cbEducationParam) {
        CbEducation detail = this.cbEducationService.getById(cbEducationParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author wj
     * @Date 2021-01-06
     */
    @RequestMapping("/list")
    public LayuiPageInfo list(CbEducationParam cbEducationParam) {
        return this.cbEducationService.findPageBySpec(cbEducationParam);
    }

    /**
     * 查询列表
     *
     * @author wj
     * @Date 2021-01-06
     */
    @RequestMapping("/list_education")
    public ResponseData listEducation(CbEducationParam cbEducationParam) {
        List<CbEducationResult> list = this.cbEducationService.findListBySpec(cbEducationParam);
        return ResponseData.success(list);
    }


    /**
     * 查询校友列表
     *
     * @author wj
     * @Date 2021-01-06
     */
    @RequestMapping("/alumniList")
    public ResponseData alumniList(CbEducationParam cbEducationParam) {
        List<CbEducationResult> list = this.cbEducationService.alumniList(cbEducationParam);
        return ResponseData.success(list);
    }

    /**
     * 校友的专业
     * @param schoolNo
     * @return
     */
    @RequestMapping("/list_profession")
    public ResponseData listProfession(String schoolNo){
        List<CbEducationResult> list = cbEducationService.listProfession(schoolNo);
        return ResponseData.success(list);
    }
}


